package main

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"news/config"
	"news/models"
	"news/routers"
)

func main() {
	conf, err := config.LoadConfig()
	if err != nil {
		panic("配置文件加载失败")
	}
	db, err := gorm.Open(mysql.Open(conf.Dsn), &gorm.Config{})
	if err != nil {
		panic("数据库连接失败")
	}
	err = db.AutoMigrate(&models.News{}, &models.User{})
	if err != nil {
		panic("数据库迁移失败")
	} else {
		fmt.Println("数据库迁移成功")
	}
	r := routers.SetupRouter(db)
	r.Run(":8080")
}
